package org.atlantis.grosbeak.pot.mapper;

import java.sql.ResultSet;
import java.sql.SQLException;

import org.atlantis.grosbeak.lang.Exceptions;
import org.atlantis.grosbeak.pot.PotException;

/**
 * 把数据库中查询出来的数据映射到一个数组中。
 * 
 * @author <a href="mailto:seenoevil.cn@gmail.com">SeeNoEvil</a>
 * 
 */
public class ArrayRowMapper extends RowMapper<Object[]> {

	public Object[] mapRow(ResultSet rs, String[] names, int[] types)
			throws SQLException {
		Object[] objs = new Object[types.length];
		for (int i = 0; i < types.length; i++) {
			int type = types[i];
			FieldMapper<?> fm = MapperKit.getFieldMapper(type);
			if (fm == null)
				throw Exceptions.makeThrow(PotException.class,
						"No FieldMapper match SQL type [%d]", type);
			objs[i] = fm.mapField(rs, type, names[i], true);
		}
		return objs;
	}
}
